package com.zyzg.controller;

import com.zyzg.domain.EquipmentSnParam;
import com.zyzg.domain.PeripheryDevParam;
import com.zyzg.domain.RealtimeParam;
import com.zyzg.service.IDataService;
import com.zyzg.utils.AjaxResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/location")
@RequiredArgsConstructor
public class ApiController {

    @Autowired
    private IDataService dataService;

    @PostMapping("/third/codeByCarInfo")
    public AjaxResult getCodeByCarInfo(@RequestBody PeripheryDevParam param) {
        if (param.getCode() == null || param.getCode().isEmpty()) {
            return AjaxResult.error("参数错误,请输入环保编号");
        }
        return AjaxResult.success(dataService.getCodeByCarInfo(param));
    }

    @PostMapping("/third/resSerialNo")
    public AjaxResult getResSerialNo(@RequestBody EquipmentSnParam param) {
        return dataService.getResSerialNo(param);
    }

    @GetMapping("/third/isInstallDev")
    public AjaxResult getIsInstallDev(String code) {
        return dataService.getIsInstallDev(code);
    }

    @PostMapping("/third/nearbyCarInfo")
    public AjaxResult getNearbyCarInfo(@RequestBody RealtimeParam param) {
        if (param.getLat() == 0 || param.getLng() == 0 || param.getRadius() == 0) {
            return AjaxResult.error("参数错误,请检测经纬和半径是否为0");
        }
        return dataService.getNearbyCarInfo(param);
    }

}